//
//  ATADJgSDKBiddingManager.m
//  AnyThinkSDKDemo
//
//  Created by 刘娟 on 2024/9/25.
//  Copyright © 2024 抽筋的灯. All rights reserved.
//

#import "ATADJgSDKBiddingManager.h"
#import "ATADJgSDKBiddingDelegate.h"

@interface ATADJgSDKBiddingManager ()

@property (nonatomic, strong) NSMutableDictionary *bidingAdStorageAccessor;
@property (nonatomic, strong) NSMutableDictionary *bidingAdDelegate;

@end

@implementation ATADJgSDKBiddingManager

+ (instancetype)sharedInstance {
    static ATADJgSDKBiddingManager *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[ATADJgSDKBiddingManager alloc] init];
        sharedInstance.bidingAdStorageAccessor = [NSMutableDictionary dictionary];
        sharedInstance.bidingAdDelegate = [NSMutableDictionary dictionary];
    });
    return sharedInstance;
}

- (ATADJgSDKBiddingRequest *)getRequestItemWithUnitID:(NSString *)unitID {
    
    return [self.bidingAdStorageAccessor objectForKey:unitID];
    
}

- (void)removeRequestItmeWithUnitID:(NSString *)unitID {
    [self.bidingAdStorageAccessor removeObjectForKey:unitID];
}

- (void)savaBiddingDelegate:(ATADJgSDKBiddingDelegate *)delegate withUnitID:(NSString *)unitID {
    [self.bidingAdDelegate setObject:delegate forKey:unitID];
}

- (void)removeBiddingDelegateWithUnitID:(NSString *)unitID {
    
    if (unitID.length) {
        [self.bidingAdDelegate removeObjectForKey:unitID];
    }
    
}

- (void)startWithRequestItem:(ATADJgSDKBiddingRequest *)request {
    
    [self.bidingAdStorageAccessor setObject:request forKey:request.unitID];
    ATADJgSDKBiddingDelegate *delegate = [[ATADJgSDKBiddingDelegate alloc] init];
    delegate.unitID = request.unitID;
    [request.customObject setValue:delegate forKey:@"containerDelegate"];
    [self savaBiddingDelegate:delegate withUnitID:request.unitID];
}


@end

